package com.iplant.ams.controller.dms.maintenance;

import com.iplant.ams.service.DRMService;
import com.iplant.ams.service.po.dms.maintenance.DMSMaintenanceStep;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/DMSMaintenanceStep")
public class DMSMaintenanceStepController extends BasicController<DMSMaintenanceStep> {
    private static Logger logger = LoggerFactory.getLogger(DMSMaintenanceStepController.class);


    public DMSMaintenanceStepController() {
        super(DMSMaintenanceStep.class);
    }

    @Autowired
    private DRMService mDRMService;

    /**
     * 查询保养步骤列表
     */
    @GetMapping("/All")
    public Object All(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            // 获取参数
            Map<String, Object> wParams = GetParamsMap(request);
            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSMaintenanceStep>> wServiceResult =
                    mDRMService.DMS_QueryMaintenanceStepAll(wLoginUser,
                            wParams, wPagination);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }

    /**
     * 查询保养步骤
     */
    @GetMapping("/Info")
    public Object Info(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            Map<String, Object> wParams = GetParamsMap(request);

            ServiceResult<DMSMaintenanceStep> wServiceResult = mDRMService.DMS_QueryMaintenanceStepInfo(wLoginUser,
                    wParams);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceResult.Result);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }
}
